import router from "./router";
import { getToken } from "@/utils/auth";

router.beforeEach(async (to, from, next) => {
  if (to.path === "/" && from.path === "/") {
    if (getToken()) {
      next({ path: "/list" });
    }
    // 不要在这里总是调用 next('/') 或 next({ path: '/' })
    next(); // 允许导航继续
  } else {
    if (!getToken()) {
      next({ path: "/" });
    }
    // 其他逻辑
    next(); // 允许导航继续
  }
});
